<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="./css/base.css" />
    <link rel="stylesheet" href="./css/分类index.css" />
    <link rel="stylesheet" href="./less/分类index.less" />
    <link rel="stylesheet" href="./首页字体图标/iconfont.css" />
  </head>
  <body>
    <div id="app">
      <!-- 头部 -->
      <header>
        <div class="head">全部分类</div>
        <!-- 搜索框 -->
        <div class="search">
          <div class="ii">
            <i class="iconfont icon-search-1-copy"></i>
            <span>搜索商品</span>
          </div>
        </div>
      </header>

      <!-- 主体内容 -->
      <main>
        <!-- 侧边栏 -->
        <div class="big">
          <a
            href="#"
            :class="{active:isactive===index}"
            v-for="(item,index) in arr"
            @click.prevent="fn(index)"
          >
            <span>{{item.name}}</span>
          </a>
        </div>
        <!-- 商品内容 -->
        <div class="right">
          <a
            href="#"
            class="tab"
            v-for="(item,index) in arr1"
            :class="{active:isactive===index}"
          >
            <img :src="item.image.external_url" alt="" />
            <p>{{item.name}}</p>
          </a>
        </div>
      </main>
      <!-- 底部 -->
      <footer>
        <a href="./首页.html">
          <i class="iconfont icon-shouye"></i>
          <p>首页</p>
        </a>
        <a href="#">
          <i class="iconfont icon-fenlei"></i>
          <p>分类</p>
        </a>
        <a href="./购物车.html">
          <i class="iconfont icon-gouwuche"></i>
          <p>购物车</p>
        </a>
        <a href="#">
          <i class="iconfont icon-wode"></i>
          <p>我的</p>
        </a>
      </footer>
    </div>
    <script src="./lib/axios.js"></script>
    <script src="./js/vue.js"></script>
    <!-- <script src="./js/分类.js"></script> -->

    <script>
      const app = new Vue({
        el: '#app',
        data: {
          isactive: 0,
          arr: [],
          arr1: []
        },
        created() {
          this.left()
        },
        methods: {
          async left() {
            const res = await axios.get(
              'http://cba.itlike.com/public/index.php?s=/api/category/list'
            )
            console.log(res.data.data.list)
            console.log(res.data.data.list[0].children)
            this.arr = res.data.data.list
            this.arr1 = res.data.data.list[0].children
          },
          fn(id) {
            console.log(id)
            this.arr1 = this.arr[id].children
          }
        }
      })
    </script>
  </body>
</html>
